package inporter;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

import main.tokens;

public class TokenArrayImporter 
{
	/*
	 * Function: Get existed token array from text file
	 * Input: pFileLocation -> File location
	 * Output: Token Array
	 */
	public ArrayList<tokens> arlInporter(String pFileLocation)
	{
		ArrayList<tokens> arlTokenAll = new ArrayList<tokens>();
		
		try
		{
			FileReader reader = new FileReader(pFileLocation);
			BufferedReader br = new BufferedReader(reader);
			String strCntLine = null;
			 
			while((strCntLine = br.readLine()) != null) 
			{
				String strToken = strCntLine.substring(0, strCntLine.indexOf("  [0]  "));
				String strLoc = strCntLine.substring(strCntLine.indexOf("  [0]  ") + 7);
				arlTokenAll.add(new tokens(strToken, strLoc));
			}
			
			br.close();
			reader.close();
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}	
		
		return arlTokenAll;
	}
}
